package com.example.springbootsfzy.controller.liujinping;

import com.example.springbootsfzy.domain.CoursePurchaseRecords;
import com.example.springbootsfzy.service.liujinping.CoursePurchaseRecordsService;
import com.example.springbootsfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
//课程购买记录表
@RestController
@RequestMapping("/coursePurchaseRecords")
public class CoursePurchaseRecordsController {
    @Autowired
    private CoursePurchaseRecordsService coursePurchaseRecordsService;
    // TODO: 实现课程购买记录相关的API接口
    @GetMapping("/getAllRecords")
    public R getAllRecords() {
        return R.ok( coursePurchaseRecordsService.getAllRecords());
    }
    @GetMapping("/getRecordsById")
    public R getRecordsById(Long id) {
        return R.ok(coursePurchaseRecordsService.getRecordsById(id));
    }

    @PostMapping
    public R addRecords(@RequestBody CoursePurchaseRecords coursePurchaseRecords) {
        int result=coursePurchaseRecordsService.addRecords(coursePurchaseRecords);
        if(result>0){
            return R.ok("添加课程购买记录成功");
        }
        return R.fail("添加课程购买记录失败");
    }
    @PutMapping("/updateRecords")
    public R updateRecords(@RequestBody  CoursePurchaseRecords coursePurchaseRecords) {
        int result=coursePurchaseRecordsService.updateRecords(coursePurchaseRecords);
        if(result>0){
            return R.ok("更新课程购买记录成功");
        }
        return R.fail("更新课程购买记录失败");
    }
    @PatchMapping
    public R updateRecordsActive(@RequestBody CoursePurchaseRecords coursePurchaseRecords) {
        int result=coursePurchaseRecordsService.updateRecordsActive(coursePurchaseRecords);
        if(result>0){
            return R.ok("更新课程购买记录状态成功");
        }
        return R.fail("更新课程购买记录状态失败");
    }
    @DeleteMapping("/deleteRecords")
    public R deleteRecords(Long id) {
        int result=coursePurchaseRecordsService.deleteRecords(id);
        if(result>0){
            return R.ok("删除课程购买记录成功");
        }
        return R.fail("删除课程购买记录失败");
    }
    //通过课程id查询购买信息
    @GetMapping("/getRecordsByCourseId")
    public R getRecordsByCourseId(Integer id) {
        return R.ok(coursePurchaseRecordsService.getRecordsByCourseId(id));
    }

}
